<script src="${ctxPath}/static/js/lay/modules/element.js"></script>
<blockquote class="layui-elem-quote" style="font-size: 14px">专家人才积分规则
</blockquote>

<hr class="layui-bg-gray">
<form class="layui-form" action="" id="expert_form">
    <div class="layui-collapse" lay-filter="expert_collapse">
        @for(expertDictDto in expertDictDtos){
        <div class="layui-colla-item">
            <h2 class="layui-colla-title">${expertDictDto.dict.name}</h2>
            <div class="layui-colla-content layui-show">

                <table class="layui-table">
                    <colgroup>
                        <col width="200">
                        <col width="200">
                        <col width="200">
                        <col width="5%">
                    </colgroup>
                    <thead>
                    <tr>
                        <th>称号</th>
                        <th>代码</th>
                        <th>积分</th>
                        <th>
                            <button type="button" class="btn btn-primary" onclick="addRow('${expertDictDto.dict.code}')" ><i class="fa fa-plus-circle"></i></button>
                        </th>
                    </tr>
                    </thead>
                    <tbody id="${expertDictDto.dict.code}_table">
                    @for(qualityGradeRule in expertDictDto.qualityGradeRules){
                    <tr>
                        <input type="hidden"  name="qualityGradeRule[${qualityGradeRuleLP.index}].gradeType" value="${expertDictDto.dict.code}" >
                        <td><input type="text" name="qualityGradeRule[${qualityGradeRuleLP.index}].grade" value="${qualityGradeRule.grade}"  class="layui-input" lay-verify="required"></td>
                        <td><input type="text" name="qualityGradeRule[${qualityGradeRuleLP.index}].gradeCode" value="${qualityGradeRule.gradeCode}"  class="layui-input" lay-verify="required"></td>
                        <td><input type="text" name="qualityGradeRule[${qualityGradeRuleLP.index}].integral" value="${qualityGradeRule.integral}" class="layui-input" lay-verify="required|number"></td>
                        <td>
                            <button type="button" class="btn btn-primary " onclick="deleteRow($(this))">
                                <i class="fa fa-trash-o"></i>
                            </button>
                        </td>
                    </tr>
                    @}
                    </tbody>
                </table>
            </div>
        </div>
        @}
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block" style="margin-top: 20px;">

            <button class="layui-btn" lay-submit lay-filter="fulltime_form" >提交保存</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

<template>
    <tr>
        <input type="hidden" id="temp_gradeType" name="qualityGradeRule[].gradeType">
        <td><input type="text" name="qualityGradeRule[].grade" autocomplete="off" class="layui-input" lay-verify="required"></td>
        <td><input type="text" name="qualityGradeRule[].gradeCode" autocomplete="off" class="layui-input" lay-verify="required"></td>
        <td><input type="text" name="qualityGradeRule[].integral" autocomplete="off" class="layui-input" lay-verify="required|number"></td>
        <td>
            <button type="button" class="btn btn-primary " onclick="deleteDegreeRow($(this))">
                <i class="fa fa-trash-o"></i>
            </button>
        </td>
    </tr>
</template>
<script>
    $(function(){
        initExpertTrain();
    });
    /**
     * 添加行
     */
    function addRow(code) {
        var trSize = $("#expert_form>tr").length + 1;
        var tbodyId = "#"+code +"_table";
        $("#temp_gradeType").attr("value",code);
        $(tbodyId).append($("template").html().replace(/\[]/g,"["+trSize+"]"));
    }

    /**
     * 删除行
     */
    function deleteDegreeRow($this) {
        $this.closest("tr").empty();
    }
    function initExpertTrain() {
        layui.use(['layer', 'form'], function(){
            var element = layui.element;
            var layer = layui.layer;
            var form = layui.form;

            //监听折叠
            element.on('collapse(expert_collapse)', function(data){

            });

            form.on('submit(expert_form)', function(data){
                form.verify();
                $.ajax({
                    type: "POST",
                    url: 'integral/fulltime_train_add',
                    data: data.field,
                    dataType: "json",
                    success: function(data){
                        Feng.success("保存成功!");
                    }
                });
                return false;
            });
        });

    }
</script>